import 'package:abc/controller/change_password_controller.dart';
import 'package:abc/view/CustomAppBar.dart';
import 'package:abc/view/GradientButton.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ChangePasswordPage extends GetView<ChangePasswordController> {
  const ChangePasswordPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (!Get.isRegistered<ChangePasswordController>()) {
      Get.lazyPut(() => ChangePasswordController());
    }
    return Scaffold(
      backgroundColor: const Color(0xFF0E0F26), // 深色背景
      body: Column(
        children: [
          // 顶部导航栏 (使用 CustomAppBar 或标准 AppBar)
          CustomAppBar(
            title: "设置账号密码",
            onBack: () {
              Get.back();
            },
          ),

          Expanded(
            child: SingleChildScrollView(
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 15),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _buildHeaderIcon(), // 顶部 Logo/图标
                    const SizedBox(height: 30),
                    _buildFormCard(), // 账号/密码输入表单
                    const SizedBox(height: 20),
                    _buildTips(),

                    // Expanded(child: Container()), // 温馨提示
                  ],
                ),
              ),
            ),
          ),
          _buildBottomButton()
        ],
      ),
    );
  }

  // ---  顶部 Logo/图标 ---
  Widget _buildHeaderIcon() {
    return Center(
      child: Padding(
        padding: const EdgeInsets.only(top: 47.0),
        child: Image.asset(
          'assets/images/ic_app_logo.png',
          width: 110,
          height: 110,
        ),
      ),
    );
  }

  // --- 表单输入区域 (账号, 密码, 确认密码) ---
  Widget _buildFormCard() {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0x33959595), // 卡片背景色
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        children: [
          SizedBox(height: 5),
          _buildInputItem(
            '账号',
            '请输入账号',
            controller: controller.accountController,
          ),
          _buildInputItem(
            '密码',
            '请输入密码',
            isPassword: true,
            controller: controller.passwordController,
          ),
          _buildInputItem(
            '确认密码',
            '请确认密码',
            isPassword: true,
            controller: controller.confirmPasswordController,
          ),
          SizedBox(height: 5),
        ],
      ),
    );
  }

  // 通用输入项 Widget
  Widget _buildInputItem(
    String label,
    String hint, {
    bool isPassword = false,
    TextEditingController? controller,
  }) {
    return Column(
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0),
          child: Row(
            children: [
              SizedBox(
                width: 80, // 固定标签宽度
                child: Text(
                  label,
                  style: const TextStyle(color: Colors.white, fontSize: 18),
                ),
              ),
              Expanded(
                child: TextField(
                  controller: controller, // 添加控制器
                  obscureText: isPassword,
                  style: const TextStyle(color: Colors.white),
                  decoration: InputDecoration(
                    hintText: hint,
                    hintStyle: TextStyle(
                      color: Colors.white.withOpacity(0.5),
                      fontSize: 15,
                    ),
                    border: InputBorder.none, // 移除下划线
                    contentPadding: const EdgeInsets.symmetric(vertical: 15),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  // ---  温馨提示 ---
  Widget _buildTips() {
    const String tipsText = """
温馨提示:
1、账号和密码必须大于等于5位字符
2、不提供密码修改功能，请牢记自己的密码
3、请勿外泄密码
""";
    return Text(
      tipsText,
      style: TextStyle(color: Color(0xFF999999), fontSize: 13, height: 1.8),
    );
  }

  // ---  底部确认按钮 ---
  Widget _buildBottomButton() {
    return Container(
      color: const Color(0xFF0E0F26), // 底部区域背景色
      padding: const EdgeInsets.fromLTRB(0, 0, 0, 15), // 包含底部安全区域
      child: GradientButton(
        text: '确定',
        onPressed: () {
          controller.submitForm();
        },
      ),
    );
  }
}
